package guard_grammar;


import java.io.IOException;
import java.util.LinkedList;

/**
 * @author Zlatka Trajcheska, Marija Petkovska
 * @version 1.0 18.02.2013 
 * 
 * In this class we will construct parse table who will help to construct the parser 
 *  */


public class ParseTable {

	LinkedList<Relation> table;
	
	/**
	 * This method is the constructor of the class.
	 */
	public ParseTable(){
		
		table=new LinkedList<Relation>();
		
		table.add(new Relation("PROPOSITIONAL", "constant" , 1));
		table.add(new Relation("PROPOSITIONAL", "variable" , 1));
		table.add(new Relation("PROPOSITIONAL", "!" , 1));
		table.add(new Relation("PROPOSITIONAL", "(" , 1));
		
		table.add(new Relation("BASE", "constant" , 2));
		table.add(new Relation("BASE", "variable" , 2));
		table.add(new Relation("BASE", "!" , 22));
		table.add(new Relation("BASE", "(" , 3));
		
		table.add(new Relation("REMAINDER", "&" , 4));
		table.add(new Relation("REMAINDER", "|" , 4));
		table.add(new Relation("REMAINDER", "=>" , 4));
		table.add(new Relation("REMAINDER", ")" , 5));
		
		table.add(new Relation("OPERATOR", "&" , 6));
		table.add(new Relation("OPERATOR", "|" , 7));
		
		table.add(new Relation("LOGIC", "constant" , 9));
		table.add(new Relation("LOGIC", "variable" , 9));
		
		table.add(new Relation("LOGIC_REMAINDER", "<" , 10));
		table.add(new Relation("LOGIC_REMAINDER", ">" , 11));
		table.add(new Relation("LOGIC_REMAINDER", "<=" , 12));
		table.add(new Relation("LOGIC_REMAINDER", ">=" , 13));
		table.add(new Relation("LOGIC_REMAINDER", "!=" , 14));
		table.add(new Relation("LOGIC_REMAINDER", "==" , 15));

		table.add(new Relation("VARIABLE", "constant" , 17 ));
		table.add(new Relation("VARIABLE", "variable" , 16));
		
		table.add(new Relation("ARITHMETIC", "constant" , 18));
		table.add(new Relation("ARITHMETIC", "variable" , 18));
		
		table.add(new Relation("ARITHMETIC_REMAINDER", "+" , 19));
		table.add(new Relation("ARITHMETIC_REMAINDER", "-" , 20));
		table.add(new Relation("ARITHMETIC_REMAINDER", "<" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", ">" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "<=" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", ">=" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "!=" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "==" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "&" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "|" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", "=>" , 21));
		table.add(new Relation("ARITHMETIC_REMAINDER", ")" , 21));
		
		//so e

		table.add(new Relation("REMAINDER", "e" , 5));
		table.add(new Relation("ARITHMETIC_REMAINDER", ")" , 21));
		
	}
	
	/**
	 * This method will return id of rule for given nonterminal and terminal
	 * 
	 * @param String nonterminal , String terminal 
	 * @return int id - id of rule 
	 * @throws IOException 
	 * */
	public int find(String nonterminal, String terminal) throws IOException
	{
        int id=0;

        for(int i=0;i<table.size();i++){
        	
        	if((table.get(i).getNonterminal().equals(nonterminal)) && (table.get(i).getTerminal().equals(terminal))){
        		
        		id= table.get(i).getID_rule();
        	}
        }
    
        return id;
    }
}
